<?php
/**
 * Created by PhpStorm.
 * User: wyl
 * Date: 2015/7/24
 * Time: 4:55
 */
include("../dbConn.php");

if($_SERVER['REQUEST_METHOD']=="POST"){
    $username = $_POST['user'];
    $password = $_POST['pass'];
    $key = $_POST['key'];
    if($key =="kaguya"){
        $passwd = md5(base64_encode($password));
        $conn = dbConn();
        $sql = sprintf("INSERT INTO users ( username, password) VALUES ('%s','%s')",mysql_real_escape_string($username),mysql_real_escape_string($passwd));
        $res = mysql_query($sql,$conn);
        if($res == true){
            echo "账号：$username\n密码：  $password";
        }else{
            echo "FAIL";
        }
    }else{
        header('HTTP/1.1 404 Not Found');
        header('status: 404 Not Found');
        exit();
    }
}else{
    $username = $_GET['user'];
    $password = $_GET['pass'];
    $key = $_GET['key'];
    if($key =="kaguya"){
        $passwd = md5(base64_encode($password));
        $conn = dbConn();
        $sql = sprintf("INSERT INTO users ( username, password) VALUES ('%s','%s')",mysql_real_escape_string($username),mysql_real_escape_string($passwd));
        $res = mysql_query($sql,$conn);
        if($res == true){
            echo "
                    <html>
                        <head>
                            <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />
                        </head>
                        <body>
                            账号：$username<br />密码：  $password
                        </body>
                    </html>
                    ";
        }else{
            echo "FAIL";
        }
    }else{
        header('HTTP/1.1 404 Not Found');
        header('status: 404 Not Found');
        exit();
    }
}